import socket

ip_port = ('127.0.0.1', 5000)
back_log = 10
buffer_size = 1024
test = "<h1>Hello World!!!<h1>"


def main():
    webserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    webserver.bind(ip_port)
    webserver.listen(back_log)
    print("waiting for connection...............")
    while True:
        conn, addr = webserver.accept()
        recvdata = conn.recv(buffer_size).decode().split("\r\n")
        print(recvdata)
        conn.sendall(bytes("HTTP/1.1 201 OK\r\n\r\n", "utf-8"))  # 响应头
        conn.sendall(bytes(test, "utf-8"))
        conn.close()


if __name__ == '__main__':
    main()
